package com.mofofa.maozy.info.kemailon

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.mofofa.maozy.R
import com.mofofa.maozy.data.RevObjWalletListFcfa
import com.mofofa.maozy.extend.isMaozyLink

class WalletListXafAdapter(val dataList: List<RevObjWalletListFcfa>) :
    RecyclerView.Adapter<WalletListXafAdapter.ViewHolder>() {

    private var mMaozyOnMaozyItemMaozyClickMaozyListener: (Int, RevObjWalletListFcfa, Int) -> Unit =
        { positon, product, actionTyp -> }

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val rl_wallet_mobile_list_content_bg: RelativeLayout =
            view.findViewById(R.id.rl_wallet_mobile_list_content_bg)
        val tv_wallet_mobile_list_mobile: TextView =
            view.findViewById(R.id.tv_wallet_mobile_list_mobile)
        val iv_wallet_mobile_list_logo: ImageView =
            view.findViewById(R.id.iv_wallet_mobile_list_logo)
        val tv_wallet_mobile_list_name: TextView =
            view.findViewById(R.id.tv_wallet_mobile_list_name)
        val v_wallet_mobile_list_delete: ImageView =
            view.findViewById(R.id.v_wallet_mobile_list_delete)
        val v_wallet_mobile_list_bottom_line: View =
            view.findViewById(R.id.v_wallet_mobile_list_bottom_line)
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.view_maozy_adpter_wallet_mobile_fcfa, parent, false)
        return ViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data: RevObjWalletListFcfa = dataList[position]
        holder.tv_wallet_mobile_list_mobile.text = data.walletMobile
        holder.tv_wallet_mobile_list_name.text = data.walletDesc

        holder.v_wallet_mobile_list_delete.setOnClickListener {
            mMaozyOnMaozyItemMaozyClickMaozyListener.invoke(position, data, 0)
        }
        if (data.walletLogo.toString().isMaozyLink()) {
            Glide.with(holder.iv_wallet_mobile_list_logo.context).load(data.walletLogo)
                .into(holder.iv_wallet_mobile_list_logo)
        }

        if (data.displayMode == 0) {
            holder.v_wallet_mobile_list_delete.visibility = View.VISIBLE
            holder.v_wallet_mobile_list_bottom_line.visibility = View.GONE
            holder.rl_wallet_mobile_list_content_bg.setBackgroundResource(R.drawable.maozy_wallet_fcfa)

        } else if (data.displayMode == 1) {
            holder.v_wallet_mobile_list_delete.visibility = View.GONE
            holder.v_wallet_mobile_list_bottom_line.visibility = View.GONE
            holder.rl_wallet_mobile_list_content_bg.setBackgroundResource(R.drawable.maozy_wallet_fcfa)

        } else if (data.displayMode == 2) {
            holder.v_wallet_mobile_list_delete.visibility = View.GONE
            holder.v_wallet_mobile_list_bottom_line.visibility = View.VISIBLE
            holder.rl_wallet_mobile_list_content_bg.setBackgroundResource(R.drawable.maozy_form_input_transparent)

        } else {
            holder.v_wallet_mobile_list_delete.visibility = View.GONE
            holder.rl_wallet_mobile_list_content_bg.setBackgroundResource(R.drawable.maozy_wallet_fcfa)
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    fun setMaozyOnMaozyItemMaozyClickMaozyListener(listener: (Int, RevObjWalletListFcfa, Int) -> Unit) {
        mMaozyOnMaozyItemMaozyClickMaozyListener = listener
    }

}